package com.akbar.mapper;

import com.akbar.pojo.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper {

    // 查询管理员信息
    @Select("select * from tb_admin")
    List<Admin> list();


    // 删除管理员信息
    @Delete("delete from tb_admin where id = #{id}")
    int delete(Integer id);


    // 新增管理员
    @Options(keyProperty = "id", useGeneratedKeys = true)
    @Insert("insert into tb_admin(username, password, salt, nickname, avatar, email, github_url, bilibili_url, gitee_url, created_time) " +
            "values(#{username},#{password},#{salt},#{nickname},#{avatar},#{email},#{githubUrl},#{bilibiliUrl},#{giteeUrl},#{createdTime})")
    int insert(Admin admin);


    // 根据id更新管理员信息
    @Update("update tb_admin set username=#{username},password=#{password},salt=#{salt},nickname=#{nickname},avatar=#{avatar}," +
            "email=#{email},github_url=#{githubUrl},bilibili_url=#{bilibiliUrl},gitee_url=#{giteeUrl},created_time=#{createdTime} where id=#{id}")
     int update(Admin admin);


    // 根据id查询管理员信息(第一种解决办法，起别名)
    @Select("select id, username, password, salt, nickname, avatar, email, " +
            "github_url githubUrl, bilibili_url bilibiliUrl, gitee_url giteeUrl, created_time createdTime " +
            "from tb_admin where id=#{id}")
    Admin getByIdOne(Integer id);


    // 根据id查询管理员信息(第二种解决办法，通过Results，Result手动封装)
    @Results({
            @Result(column = "github_url", property = "githubUrl"),
            @Result(column = "bilibili_url", property = "bilibiliUrl"),
            @Result(column = "gitee_url", property = "giteeUrl"),
            @Result(column = "created_time", property = "createdTime")
    })
    @Select("select * from tb_admin where id=#{id}")
    Admin getByIdTwo(Integer id);


    // 第三种方案开启mybatis驼峰命名开关
    @Select("select * from tb_admin where id=#{id}")
    Admin getByIdThree(Integer id);


    // 模糊查询
    @Select("select * from tb_admin where username like concat('%', #{name}, '%')")
    List<Admin> likeList(String name);

    List<Admin> xmlList(String name);
}
